/*
 * Copyright (c) 2006-2021, Halo team
 *
 * SPDX-License-Identifier: GPLv3
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-09-11     Eywen        the first version
 */

#ifndef HARD_TASK_H
#define HARD_TASK_H

#include <stdint.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <stdbool.h>
#include "drivers/hwtimer.h"

typedef struct _hard_task_ops hard_task_ops_t;
//
///* 任务节点 */
//typedef struct _task_node{
//    //struct _task_node *prev;
//    void (*task)(void *para);
//    void *para;
//    struct _task_node *next;
//}task_node_t;
//
///* 任务队列头部 */
//typedef struct _task_head{
//    task_node_t *task_node;
//    int task_cnt;
//}task_head_t;

typedef rt_err_t (*hard_task_run_schdule_cb)(rt_device_t dev, rt_size_t size);

/* 任务对象定义 */
typedef struct _hard_task{
    rt_device_t hard_timer;            /* 定时器设备句柄 */
    //task_head_t task_list;

    uint32_t freq;                     /* 定时器中断频率 */
    const hard_task_ops_t *ops;
}hard_task_t;



typedef void (*hard_task_fun)(void *para);

typedef struct _hard_task_ops{
    bool (*init)(hard_task_t *task, const char *timer_name, uint32_t freq);
    bool (*start)(hard_task_t *task, uint32_t freq);
    bool (*stop)(hard_task_t *task);
    bool (*set_run)(hard_task_t *task, hard_task_run_schdule_cb cb);
    //void (*run_once)(hard_task_t *task);
    //bool (*task_add)(hard_task_t *task, hard_task_fun task_fun, void *para);
    //void (*run_once)(hard_task_t *task);
}hard_task_ops_t;

bool hard_task_register(hard_task_t *task);
hard_task_t *hard_task_creater(void);

#endif // HARD_TASK_H
